import 'dart:ui';

import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/utils/string_utils.dart';

import '../../../utils/common_utils.dart';
import '../../../widget/w_toast.dart';

class BookManageModel {
  //已预约、签约中、待开始、试驾中、已结束、已取消
  static Map exchangeStatus(status) {
    Map map = {"color": WColors.green, "pressText": "", "openFlag": true};

    if (status == "已预约") {
      map = {"color": WColors.green, "pressText": "确认", "openFlag": true};
    } else if (status == "已确认") {
      map = {"color": WColors.orange, "pressText": "", "openFlag": false};
    } else if (status == "已取消") {
      map = {"color": WColors.CCCCCCC, "pressText": "", "openFlag": false};
    }
    return map;
  }

  /**
   * 校验表单必填项
   */
  static bool check(Map params) {
    //校验客户名称
    if (CommonUtils.isEmptyOrNull(params["customerName"])) {
      Toast.toast("请填写客户名称");
      return false;
    }

    //校验手机号
    var flag = StringUtils.isChinaPhoneLegal(params["phone"]);
    if (!flag) {
      Toast.toast("请填写正确的手机号码");
      return false;
    }

    if (CommonUtils.isEmptyOrNull(
        StringUtils.safeGetValue(params["appointType"]))) {
      Toast.toast("请选择预约类型");
      return false;
    }
    // if (CommonUtils.isEmptyOrNull(params["modelId"])) {
    //   Toast.toast("请选择车型");
    //   return false;
    // }
    //校验接待顾问
    if (CommonUtils.isEmptyOrNull(params["saleMan"].toString())) {
      Toast.toast("请选择接待顾问");
      return false;
    }
    if (params["arriveDate"].toString() == "") {
      Toast.toast("请填写到店日期");
      return false;
    }
    if (params["appointTime"].toString() == "") {
      Toast.toast("请填写到店时间");
      return false;
    }
    return true;
  }

  static bool isDateBeforeToday(DateTime selectedDate) {
    DateTime now = DateTime.now();
    DateTime today = DateTime(now.year, now.month, now.day);
    return selectedDate.isBefore(today);
  }

  static bool isValidTime(DateTime selectedDate) {
    DateTime now = DateTime.now();
    DateTime today = DateTime(now.year, now.month, now.day);
    // 检查选中的日期是否是今天
    if (selectedDate.year == today.year &&
        selectedDate.month == today.month &&
        selectedDate.day == today.day) {
      // 如果是今天，检查时间是否早于当前时间
      return selectedDate.isAfter(now);
    }
    // 如果不是今天,直接跳过校验
    return true;
  }
}
